

init();

function init() {
    //1.查询进度列表
    queryInspectList();
}

/**
 * 检测详情
 */
function queryInspectDetail(id) {
    $.ajax({
        url :   "inspect/getinspect",
        type:   "post",
        data:JSON.stringify({
            inspectId : id
        }),
        contentType:"application/json;",
        success:function(data){
            goToLogin(data);
            console.log(data);
            var inspectDetail = data.data;
            $("#projectName").val(inspectDetail.projectName);
            $("#teamName1").val(inspectDetail.teamName);
            $("#teamDesc").val(inspectDetail.teamDesc);
            $("#personLiableName").val(inspectDetail.personLiableName);
            $("#personLiablePhone").val(inspectDetail.personLiablePhone);
            $("#inspectStartResult").val(inspectDetail.inspectStartResult);
            $("#inspectEndResult").val(inspectDetail.inspectEndResult);
            $("#fileUrl").val(inspectDetail.fileUrl);
            $("#oprUserName").val(inspectDetail.oprUserName);
            $("#oprDate").val(new Date(inspectDetail.oprDate).toLocaleDateString());
            if (inspectDetail.inspectState==1){
                $("#inspectState").val("质量检测");
            }else{
                $("#inspectState").val("安全检测");
            }m

        }
    });
}

/**
 * 检测列表
 */
function queryInspectList(pageIndex) {

    var name = "";
    name = $("#name").val();
    if(pageIndex == null){
        pageIndex = 0;
    }
    $.ajax({

        url :   prefixUrl + "inspect/selectinspect",
        type:   "post",
        data:JSON.stringify({
            teamName : name,
            personLiableName:name,
            inspectState : $("#state").val(),
            pageIndex : pageIndex
        }),
        contentType:"application/json;",
        success:function(data){
            goToLogin(data);
            var list = data.data.rows;
            console.log(list);
            var inspectHtml  = '<thead>'
                +'<tr>'
                +'<th>序号</th>'
                +'<th>施工小队名称</th>'
                +'<th>负责人名称</th>'
                +'<th>操作/申请时间</th>'
                +'<th>操作</th>'
                +'</tr>'
                +'</thead>'
                +'<tbody>';
            for(var i=0; i<list.length; i++){
                var colorStr = "red";
                if(list[i].inspectEndState == 1 || list[i].status == 1){
                    colorStr = "#00ad45";
                }
                inspectHtml = inspectHtml
                    +'<tr>'
                    +'<td>' + (parseInt(i) + 1) + '</td>'
                    +'<td><p style="color: ' + colorStr + '">'
                    +list[i].teamName
                    +'</p></td>'
                    +'<td><p style="color: ' + colorStr + '">'
                    +list[i].personLiableName
                    +'</p></td>'
                    +'<td><p style="color: ' + colorStr + '">'
                    +new Date(list[i].oprDate).toLocaleDateString()
                    +'</p></td>'
                    +'<td>'
                    +'<button type="button" class="btn btn-info mar-r-5" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo" onclick=queryInspectDetail("'
                    + list[i].inspectId
                    +'")><i class="glyphicon glyphicon-search"></i></button>'
                    +'</td>'
                    +'</tr>';
            }
            inspectHtml = inspectHtml + +'</tbody>';
            $("#inspectList").html(inspectHtml);


            var total = data.data.total;
            var remainder = total%20;
            var allNumber = 0;
            if(remainder > 0){
                allNumber = parseInt(total/20) + 1;
            }else{
                allNumber = parseInt(total/20);
            }
            var number = 1;
            var numberHtml = '<li><a onclick=queryInspectList('+ "0" +')>«</a></li>';
            for(var i=0; i<allNumber; i++){
                var id = "query-" + i;
                if(i == 0){
                    numberHtml = numberHtml
                        +'<li id="'+ id + '" name="queryList" class="active"><a onclick=queryInspectList('+ i +')>' + number + '</a></li>';
                }else{
                    numberHtml = numberHtml
                        +'<li id="'+ id + '" name="queryList"><a onclick=queryInspectList('+ i +')>' + number + '</a></li>';
                }
                number++;
            }
            numberHtml = numberHtml + '<li><a onclick=queryInspectList('+ (allNumber-1) +')>»</a></li>';
            $("#queryList").html(numberHtml);
        }
    });
}